package com.zjg.dao.impl;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.common.dao.BaseDao;
import com.common.entity.A_noticeType;
import com.common.entity.A_reply;
import com.zjg.dao.NoticeTypeDao;

public class NoticeTypeDaoImpl extends BaseDao<A_noticeType> implements NoticeTypeDao {

	@Override
	public List<A_noticeType> findByCondition(Map<String, Object> map) {
		List<Object> paramList=new ArrayList<Object>();
		StringBuffer sf=new StringBuffer();
		sf.append(" select * from A_noticeType where 1=1 ");
		if(map!=null && map.size()>0){
			if(map.get("customer_id")!=null){
				sf.append("and customer_id=? ");
				paramList.add(map.get("customer_id"));
			}
			if(map.get("start_time")!=null){
				String str=(String) map.get("start_time");
				sf.append("and start_time > to_date('?','yyyy-mm-dd hh24:mi:ss')");
				if(str.contains("&"))
				{
					sf.append("and start_time < to_date('?','yyyy-mm-dd hh24:mi:ss')");
					String time[]=str.split("&");
					paramList.add(time[0]);
					paramList.add(time[1]);
				}
				else
				{
					paramList.add(str);
				}
			}
		}
		return this.findBySql(sf.toString(), paramList.toArray());
	}

	@Override
	public A_noticeType findById(Integer id) {
		List<Object> paramList=new ArrayList<Object>();
		StringBuffer sf=new StringBuffer();
		sf.append(" select * from A_noticeType where noticeType_id=? ");
		paramList.add(id);
		List<A_noticeType> list=this.findBySql(sf.toString(), paramList.toArray());
		return (list!=null && list.size()>0)?list.get(0):null;
	}

	@Override
	public Object saveNoticeType(A_noticeType entity) {
		String sql="insert into A_noticeType(noticeType_id,name) values(seq_a_noticeType.nextval,?)";
		List<Object> paramList=new ArrayList<Object>();
		paramList.add(entity.getName());
		return this.executeUpdate(sql, paramList.toArray(),new String[]{"noticeType_id"});
	}

	@Override
	public int deleteNoticeType(Integer id) {
		String sql="delete A_noticeType where noticeType_id=?";
		return (Integer) this.executeUpdate(sql, new Object[]{id},null);
	}

	@Override
	public int updateNoticeType(A_noticeType entity) {
		String sql="update A_noticeType set name=? where noticeType_id=?";
		List<Object> paramList=new ArrayList<Object>();
		paramList.add(entity.getName());
		paramList.add(entity.getNoticeType_id());
		return (Integer) this.executeUpdate(sql, paramList.toArray(),null);
	}

	@Override
	public A_noticeType getEntity(ResultSet rs) {
		try {
			A_noticeType entity=new A_noticeType();
			entity.setNoticeType_id(rs.getInt("NoticeType_id"));
			entity.setName(rs.getString("Name"));
			return entity;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
